package org.teachertools.web.forms;

import org.teachertools.common.ValidationUtils;
import org.teachertools.data.Eleve;

public class EleveFormMapping {

    public static Eleve mappingFormToDTO(EleveForm eleveForm) {
        return mappingFormToDTO(eleveForm, new Eleve());
    }

    public static Eleve mappingFormToDTO(EleveForm eleveForm, Eleve eleve) {

        if (ValidationUtils.isNotEmpty(eleveForm.getId())) {
            eleve.setId(eleveForm.getId());
        }
        if (ValidationUtils.isNotEmpty(eleveForm.getPrenom())) {
            eleve.setPrenom(eleveForm.getPrenom());
        }
        if (ValidationUtils.isNotEmpty(eleveForm.getNom())) {
            eleve.setNom(eleveForm.getNom());
        }
        if (ValidationUtils.isNotEmpty(eleveForm.getClasse())) {
            eleve.setClasse(eleveForm.getClasse());
        }
        return eleve;
    }

    public static void mappingDTOToForm(Eleve eleve, EleveForm eleveForm) {
        eleveForm.reset();

        if (ValidationUtils.isNotEmpty(eleve.getId())) {
            eleveForm.setId(eleve.getId());
        }

        if (ValidationUtils.isNotEmpty(eleve.getPrenom())) {
            eleveForm.setPrenom(eleve.getPrenom());
        }

        if (ValidationUtils.isNotEmpty(eleve.getNom())) {
            eleveForm.setNom(eleve.getNom());
        }

        if (ValidationUtils.isNotEmpty(eleve.getClasse())) {
            eleveForm.setClasse(eleve.getClasse());
        }
    }
}
